﻿using System; 
using System.Text;
using System.Collections.Generic; 
using System.Data;
using Sasc.PV.Common;
using Sasc.PV.Common.DEncrypt;
namespace Sasc.PV.DAL
{
	[Serializable]
	public partial class ERPSerils
	{		
        
        #region Ctor
        public ERPSerils()
        {
      	      	_id=(int)0;
      			_serilsstr= "";
      			_datestr= "";
      			_usernum= "";
      			_danweistr= "";
       }
        #endregion

        #region Other Methods
        public void UpdateSerils(string serilsStr, string dataStr, string danWeiStr, string userNum)
        {
            var sql = "update ERPSerils set SerilsStr='" + Utils.ProcessSqlStr(serilsStr) + "',DateStr='" + Utils.ProcessSqlStr(dataStr) + "',DanWeiStr='" + Utils.ProcessSqlStr(danWeiStr) + "',UserNum='" + Utils.ProcessSqlStr(userNum) + "'";
           DbHelperSQL.ExecuteSQL(sql);
        }

        public bool ValidateSerilsMatch()
        {
            try
            {
                string nowSerils = DbHelperSQL.GetSHSL("select top 1 SerilsStr from ERPSerils");
                return DESEncrypt.Encrypt(Utils.GetMacAddress(), Constants.SerialNumEncryptKey).ToString() == nowSerils;
            }
            catch (Exception e)
            { 
            }
            return false;
        }
        public bool ValidateSerilsExpired()
        {
            try
            {
                var serialDate = DateTime.MinValue;
                return DateTime.TryParse(DESEncrypt.Decrypt(DbHelperSQL.GetSHSL("select top 1 DateStr from ERPSerils"), Constants.SerialNumEncryptKey), out serialDate) && serialDate >= DateTime.Now;
            }
            catch (Exception e)
            { 
            }
            return false;
        }
        #endregion
    }
}